package com.example.service;

import com.alibaba.fastjson2.JSONObject;
import com.example.domain.Entry;
import com.example.domain.Entry;
import com.example.domain.User;
import com.example.domain.vo.EntryVO;
import com.example.domain.vo.StoreVO;
import com.example.mapper.EntryMapper;
import com.example.mapper.StoreMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class EntryService {

    @Autowired
    private EntryMapper mapper;


    public PageInfo<EntryVO> selectPageList(Entry entry) {
        Integer pageNum = entry.getPageNum();
        PageHelper.startPage(pageNum, 10);
        List<EntryVO> list = mapper.selectPageList(entry);
        return new PageInfo<>(list);
    }

    public void save(Entry entry, User operator) {
        if (entry.getEntryId() == null) {
            entry.setCreateTime(new Date());
            this.mapper.insert(entry);
        } else {
            this.mapper.updateByPrimaryKeySelective(entry);
        }
    }

    public Entry selectById(Long id) {
        return this.mapper.selectByPrimaryKey(id);
    }

    public void deleteById(Long id) {
        this.mapper.deleteByPrimaryKey(id);
    }
}
